var t = getApp();

Page({
    data: {
        category_id: "",
        articleList: [],
        isLoadMore: !0,
        page: 1,
        total_page: 0
    },
    onLoad: function(t) {
        this.setData({
            category_id: t.category_id
        }), this._getData();
    },
    _getData: function(a) {
        var e = this;
        t._getNetWork({
            url: t.getNetAddresss("plugin.article.api.article.get-articles"),
            data: {
                category_id: e.data.category_id,
                page: 1
            },
            success: function(t) {
                if (1 == t.data.result) {
                    var i = t.data.data;
                    e.setData({
                        total_page: i.articles.last_page,
                        articleList: i.articles.data
                    }), wx.setNavigationBarTitle({
                        title: i.title
                    }), null != a && a(t);
                } else console.error(t), this.setData({
                    page: this.data.page - 1,
                    isLoadMore: !1
                });
            },
            fail: function(t) {
                console.error(t);
            }
        });
    },
    _getMoreData: function() {
        var a = this, e = t.getNetAddresss("plugin.article.api.article.get-articles") + "&category_id=" + this.data.category_id;
        this.data.page >= this.data.total_page ? a.setData({
            isLoadMore: !1
        }) : (a.setData({
            page: this.data.page + 1
        }), e += "&page=" + a.data.page, t._getNetWork({
            url: e,
            success: function(t) {
                if (1 == t.data.result) {
                    var e = t.data.data;
                    a.setData({
                        isLoadMore: !0,
                        articleList: a.data.articleList.concat(e.articles.data)
                    });
                } else a.setData({
                    page: a.data.page - 1,
                    isLoadMore: !1
                });
            },
            fail: function(t) {
                console.log(t);
            }
        }));
    },
    toArticle: function(t) {
        var a = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageA/member/article/articleContent/articleContent?article_id=" + a
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {
        this.setData({
            isLoadMore: !0,
            page: 1,
            total_page: 0
        }), this._getData();
    },
    onReachBottom: function() {
        this.data.isLoadMore ? this._getMoreData() : console.log("没有更多数据");
    },
    onShareAppMessage: function() {},
    onShareTimeline: function() {}
});